package luanluan.display.bitmap 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.utils.Dictionary;
	
	/**
	 * 将一张位图切割成若干位图组成动画
	 * @author luanluan
	 */
	public class BitmapRectAni
	{
		private var _bitmapData:BitmapData;
		private var _rWidth:Number;
		private var _rHeight:Number;
		private var _frameRate:uint;
		private var _col:uint;
		private var _row:uint;
		
		private var _container:Sprite;
		private var _currentFrame:uint = 1;
		private var _totalFrames:uint;
		
		private var _frames:Vector.<Bitmap>;
		
		public function BitmapRectAni(source:BitmapData , rectWidth:Number , rectHeight:Number , frameRate:uint = 30) 
		{
			_bitmapData = source;
			_rWidth 	= rectWidth;
			_rHeight 	= rectHeight;
			_frameRate 	= frameRate;
			init();
		}
		
		private function init():void 
		{
			_col 			= Math.floor(_bitmapData.width / _rWidth) < 1 ? 1 :Math.floor(_bitmapData.width / _rWidth);
			_row 			= Math.floor(_bitmapData.height / _rHeight) < 1 ? 1:Math.floor(_bitmapData.height / _rHeight) < 1;
			_totalFrames 	= _col * +_row;
			_frames 		= new Vector.<Bitmap>(_totalFrames , true);
			for (var i:int = 0; i < _row ; i++) 
			{
				for (var j:int = 0; j < _col; j++) 
				{
					var bitmap:Bitmap = new Bitmap();
					var bitmapData:BitmapData = _bitmapData.copyPixels(_bitmapData, new Rectangle(i * _rWidth , j * _rHeight , _rWidth, _rHeight));
					bitmap.bitmapData = bitmapdata;
					_frames[i * _row + j] = bitmap;
				}
			}
			
			_container = new Sprite();
		}
		
		public function gotoAndStop(targetFrame:uint):void
		{
			
		}
		
		public function gotoAndPlay(targetFrame:uint):void
		{
			
		}
		
		public function play():void
		{
			
		}
		
		public function stop():void
		{
			
		}
		
		public function addFramsScript(frame:uint , func:Function):void
		{
			
		}
		
	}

}